package org.zfes.snowier.xyz.analysis.queue;

import java.util.Collection;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;

public class SnowierQueue extends ConcurrentLinkedQueue{
	
	private String topic;
	
	private AtomicInteger size = new AtomicInteger(0);
	
	public SnowierQueue(String topic) {
		this.topic=topic;
	}

	public String getTopic() {
		return topic;
	}

	public void setTopic(String topic) {
		this.topic = topic;
	}

	@Override
	public boolean add(Object e) {
		boolean isOk=super.add(e);
		if(isOk) {
			size.incrementAndGet();
		}
		return isOk;
	}
	
	@Override
	public boolean addAll(Collection c) {
		boolean isOk=super.addAll( c);
		if(isOk) {
			size.incrementAndGet();
		}
		return isOk;
	}
	
	@Override
	public boolean offer(Object e) {
		boolean isOk=super.offer(e);
		if(isOk) {
			size.incrementAndGet();
		}
		return isOk;
	}

	@Override
	public Object poll() {
		Object obj= super.poll();
		if(obj!=null) {
			size.decrementAndGet();
		}
		return obj;
	}

	@Override
	public int size() {
		return size.intValue();
	}

	@Override
	public boolean remove(Object o) {
		boolean isOk=super.remove( o);
		if(isOk) {
			size.incrementAndGet();
		}
		return isOk;
	}

	@Override
	public void clear() {
		super.clear();
		size.set(0);
	}



	
	
	
}
